home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / ktar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.4 KB  |  171 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 2000 David Faure <faure@kde.org>
  3.    Copyright (C) 2003 Leo Savernik <l.savernik@aon.at>
  4.  
  5.    This library is free software; you can redistribute it and/or
  6.    modify it under the terms of the GNU Library General Public
  7.    License version 2 as published by the Free Software Foundation.
  8.  
  9.    This library is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  12.    Library General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU Library General Public License
  15.    along with this library; see the file COPYING.LIB.  If not, write to
  16.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17.    Boston, MA 02110-1301, USA.
  18. */
  19. #ifndef __ktar_h
  20. #define __ktar_h
  21.  
  22. #include <sys/stat.h>
  23. #include <sys/types.h>
  24.  
  25. #include <qdatetime.h>
  26. #include <qstring.h>
  27. #include <qstringlist.h>
  28. #include <qdict.h>
  29.  
  30. #include <karchive.h>
  31.  
  32. /**
  33.  * A class for reading / writing (optionally compressed) tar archives.
  34.  *
  35.  * KTar allows you to read and write tar archives, including those 
  36.  * that are compressed using gzip or bzip2.
  37.  * 
  38.  * @author Torben Weis <weis@kde.org>, David Faure <faure@kde.org>
  39.  */
  40. class KIO_EXPORT KTar : public KArchive
  41. {
  42. public:
  43.     /**
  44.      * Creates an instance that operates on the given filename
  45.      * using the compression filter associated to given mimetype.
  46.      *
  47.      * @param filename is a local path (e.g. "/home/weis/myfile.tgz")
  48.      * @param mimetype "application/x-gzip" or "application/x-bzip2"
  49.      * Do not use application/x-tgz or similar - you only need to
  50.      * specify the compression layer !  If the mimetype is omitted, it
  51.      * will be determined from the filename.
  52.      */
  53.     KTar( const QString& filename, const QString & mimetype = QString::null );
  54.  
  55.     /**
  56.      * Creates an instance that operates on the given device.
  57.      * The device can be compressed (KFilterDev) or not (QFile, etc.).
  58.      * @warning Do not assume that giving a QFile here will decompress the file,
  59.      * in case it's compressed!
  60.      * @param dev the device to read from. If the source is compressed, the
  61.      * QIODevice must take care of decompression
  62.      */
  63.     KTar( QIODevice * dev );
  64.  
  65.     /**
  66.      * If the tar ball is still opened, then it will be
  67.      * closed automatically by the destructor.
  68.      */
  69.     virtual ~KTar();
  70.  
  71.     /**
  72.      * The name of the tar file, as passed to the constructor
  73.      * Null if you used the QIODevice constructor.
  74.      * @return the name of the file, or QString::null if unknown
  75.      */
  76.     QString fileName() { return m_filename; } // TODO KDE4 const
  77.  
  78.     /**
  79.      * Special function for setting the "original file name" in the gzip header,
  80.      * when writing a tar.gz file. It appears when using in the "file" command,
  81.      * for instance. Should only be called if the underlying device is a KFilterDev!
  82.      * @param fileName the original file name
  83.      */
  84.     void setOrigFileName( const QCString & fileName );
  85.  
  86.     // TODO(BIC) make virtual. For now it must be implemented by virtual_hook.
  87.     bool writeSymLink(const QString &name, const QString &target,
  88.                 const QString &user, const QString &group,
  89.                 mode_t perm, time_t atime, time_t mtime, time_t ctime);
  90.     virtual bool writeDir( const QString& name, const QString& user, const QString& group );
  91.     // TODO(BIC) make virtual. For now it must be implemented by virtual_hook.
  92.     bool writeDir( const QString& name, const QString& user, const QString& group,
  93.                 mode_t perm, time_t atime, time_t mtime, time_t ctime );
  94.     virtual bool prepareWriting( const QString& name, const QString& user, const QString& group, uint size );
  95.     // TODO(BIC) make virtual. For now it must be implemented by virtual_hook.
  96.     bool prepareWriting( const QString& name, const QString& user,
  97.                 const QString& group, uint size, mode_t perm,
  98.                    time_t atime, time_t mtime, time_t ctime );
  99.     virtual bool doneWriting( uint size );
  100.  
  101. protected:
  102.     /**
  103.      * Opens the archive for reading.
  104.      * Parses the directory listing of the archive
  105.      * and creates the KArchiveDirectory/KArchiveFile entries.
  106.      * @param mode the mode of the file
  107.      */
  108.     virtual bool openArchive( int mode );
  109.     virtual bool closeArchive();
  110.  
  111. private:
  112.     /**
  113.      * @internal
  114.      */
  115.     void prepareDevice( const QString & filename, const QString & mimetype, bool forced = false );
  116.  
  117.     /**
  118.      * @internal
  119.      * Fills @p buffer for writing a file as required by the tar format
  120.      * Has to be called LAST, since it does the checksum
  121.      * (normally, only the name has to be filled in before)
  122.      * @param mode is expected to be 6 chars long, [uname and gname 31].
  123.      */
  124.     void fillBuffer( char * buffer, const char * mode, int size, time_t mtime,
  125.             char typeflag, const char * uname, const char * gname );
  126.  
  127.     /**
  128.      * @internal
  129.      * Writes an overlong name into a special longlink entry. Call this
  130.      * if the file name or symlink target (or both) are longer than 99 chars.
  131.      * @p buffer buffer at least 0x200 bytes big to be used as a write buffer
  132.      * @p name 8-bit encoded file name to be written
  133.      * @p typeflag specifying the type of the entry, 'L' for filenames or
  134.      *        'K' for symlink targets.
  135.      * @p uname user name
  136.      * @p gname group name
  137.      */
  138.     void writeLonglink(char *buffer, const QCString &name, char typeflag,
  139.             const char *uname, const char *gname);
  140.  
  141.     Q_LONG readRawHeader(char *buffer);
  142.     bool readLonglink(char *buffer,QCString &longlink);
  143.     Q_LONG readHeader(char *buffer,QString &name,QString &symlink);
  144.  
  145.     QString m_filename;
  146. protected:
  147.     virtual void virtual_hook( int id, void* data );
  148.     bool prepareWriting_impl(const QString& name, const QString& user,
  149.                 const QString& group, uint size, mode_t perm,
  150.                 time_t atime, time_t mtime, time_t ctime);
  151.     bool writeDir_impl(const QString& name, const QString& user,
  152.                 const QString& group, mode_t perm,
  153.                 time_t atime, time_t mtime, time_t ctime );
  154.     bool writeSymLink_impl(const QString &name, const QString &target,
  155.                 const QString &user, const QString &group,
  156.                 mode_t perm, time_t atime, time_t mtime, time_t ctime);
  157. private:
  158.     class KTarPrivate;
  159.     KTarPrivate * d;
  160. };
  161.  
  162. /**
  163.  * Old, deprecated naming
  164.  */
  165. #define KTarGz KTar
  166. #define KTarEntry KArchiveEntry
  167. #define KTarFile KArchiveFile
  168. #define KTarDirectory KArchiveDirectory
  169.  
  170. #endif
  171.